package com.jinzhi.eventresource.controller;


import java.util.*;

import com.jinzhi.eventresource.main.EventresourceModuleDO;
import com.jinzhi.eventresource.service.EventresourceModuleService;
import com.jinzhi.eventresource.vo.MatchTypeVO;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.jinzhi.common.annotation.Log;
import com.jinzhi.common.base.BaseController;
import com.jinzhi.common.utils.Result;

/**
 * 
 * <pre>
 * 赛项资源模块表
 * xzy
 * </pre>
 * <small> 2024-04-03 11:01:13 | lance</small>
 */
@Controller
@RequestMapping("/jzweb/eventresourceModule")
public class EventresourceModuleController extends BaseController {
	@Autowired
	private EventresourceModuleService eventresourceModuleService;
	
	@GetMapping()
	@RequiresPermissions("jzweb:eventresourceModule:eventresourceModule")
	String EventresourceModule(){
	    return "eventresource/eventresourceModule/eventresourceModule";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("jzweb:eventresourceModule:eventresourceModule")
	public Result<Page<EventresourceModuleDO>> list(EventresourceModuleDO eventresourceModuleDTO){
		// 查询列表数据
		Page<EventresourceModuleDO> page = eventresourceModuleService.selectPage(getPage(EventresourceModuleDO.class),
					eventresourceModuleService.convertToEntityWrapper().orderBy("id", false));
		List list = new ArrayList();
		for (int i = 0; i < page.getRecords().size(); i++) {
				EventresourceModuleDO obj = (EventresourceModuleDO) page.getRecords().get(i);
			list.add(obj);
		}
		page.setRecords(list);
        return Result.ok(page);
	}
	
	@GetMapping("/add")
	@RequiresPermissions("jzweb:eventresourceModule:add")
	String add(){
	    return "eventresource/eventresourceModule/add";
	}

	@GetMapping("/edit/{id}")
	@RequiresPermissions("jzweb:eventresourceModule:edit")
	String edit(@PathVariable("id") Long id,Model model){
		EventresourceModuleDO eventresourceModule = eventresourceModuleService.selectById(id);

		//0赛项资源 1证书资源 2行业资源 3技能培训 4课程资源 5其他资源：

		model.addAttribute("eventresourceModule", eventresourceModule);
	    return "eventresource/eventresourceModule/edit";
	}
	
	@Log("添加赛项资源模块表")
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("jzweb:eventresourceModule:add")
	public Result<String> save( EventresourceModuleDO eventresourceModule){
		eventresourceModuleService.insert(eventresourceModule);
        return Result.ok();
	}
	
	@Log("修改赛项资源模块表")
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("jzweb:eventresourceModule:edit")
	public Result<String>  update( EventresourceModuleDO eventresourceModule){
		boolean update = eventresourceModuleService.updateById(eventresourceModule);
		return update ? Result.ok() : Result.fail();
	}
	
	@Log("删除赛项资源模块表")
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("jzweb:eventresourceModule:remove")
	public Result<String>  remove( Long id){

		//eventresourceModuleService.deleteById(id);
        return Result.fail("暂不能进行删除");
	}
	
	@Log("批量删除赛项资源模块表")
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("jzweb:eventresourceModule:batchRemove")
	public Result<String>  remove(@RequestParam("ids[]") Long[] ids){
	//	eventresourceModuleService.deleteBatchIds(Arrays.asList(ids));
		return Result.fail("暂不能进行删除");
	}

	/**
	 * @auther: ak
	 * @Description 获取赛项资源类型列表
	 * @param:
	 * @return:
	 * @date: 2024/4/10 13:41
	 */
	@Log("获取赛项资源类型列表")
	@GetMapping("/getMatchTypeList")
	@ResponseBody
	public Result<List<MatchTypeVO>> getMatchTypeList() {
		ArrayList<MatchTypeVO> matchTypeList = new ArrayList<>();
		List<EventresourceModuleDO> eventresourceModuleDOS = eventresourceModuleService.selectList(null);
		for (EventresourceModuleDO eventresourceModuleDO : eventresourceModuleDOS) {
			Integer type = eventresourceModuleDO.getType();
			//0 赛项资源 1 证书资源 2 行业资源 3 技能培训 4金职大讲堂 5其他资源
			MatchTypeVO matchTypeVo = new MatchTypeVO();
			switch (type) {
				case 0: matchTypeVo.setType(0); matchTypeVo.setName("赛项资源");break;
				case 1: matchTypeVo.setType(1); matchTypeVo.setName("证书资源");break;
				case 2: matchTypeVo.setType(2); matchTypeVo.setName("行业资源");break;
				case 3: matchTypeVo.setType(3); matchTypeVo.setName("技能培训");break;
				case 4: matchTypeVo.setType(4); matchTypeVo.setName("金职大讲堂");break;
				case 5: matchTypeVo.setType(5); matchTypeVo.setName("其他资源");break;
			}
			matchTypeList.add(matchTypeVo);
		}
		return Result.ok(matchTypeList);
	}
}
